<template>
  <view class="pics">
    <scroll-view
      scroll-y
      class="left"
    >
      <view
        v-for="(item,index) in getlists"
        :key="item.id"
        :class="active===index?'active':''"
        @click="leftclick(index,item.id)"
      >
        {{item.title}}
      </view>
    </scroll-view>

    <scroll-view
      scroll-y
      class="right"
    >
      <view
        v-for="item in imglist"
        :key="item.id"
      >
        <image
          :src="item.img_url"
          @click="previewImage(item.img_url)"
        ></image>
        <text>{{item.title}}</text>
      </view>
      <text v-if="imglist.length===0">暂无数据</text>
    </scroll-view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      active: 0,
      getlists: [],
      imglist: [],
    };
  },
  onLoad() {
    this.getList();
  },
  methods: {
    getList() {
      uni.request({
        url: "http://localhost:8082/api/getimgcategory",
        success: (res) => {
          console.log(res);
          this.getlists = res.data.message;
          console.log(this.getlists);
        },
      });
    },
    leftclick(index, id) {
      this.active = index;
      uni.request({
        url: "http://localhost:8082/api/getimages/" + id,
        success: (res) => {
          console.log(res.data);
          this.imglist = res.data.message;
          console.log(this.imglist);
        },
      });
    },
    previewImage(current) {
      const urls = this.imglist.map((item) => {
        return item.img_url;
      });
      console.log(urls);
      uni.previewImage({
        urls: urls,
        loop: true,
        current,
      });
    },
  },
};
</script>

<style lang="scss">
page {
  height: 100%;
}
.pics {
  height: 100%;
  display: flex;
  .right {
    width: 550rpx;
  }
  .left {
    width: 200rpx;
    height: 100%;
    overflow: hidden;
    // background: red;
    border-right: 1px solid;
    // border-bottom: 1px ;
    view {
      height: 150rpx;
      line-height: 150rpx;
      font-size: 45rpx;
      text-align: center;
      border-top: 1px solid #eee;
    }
    .active {
      background: red;
      color: white;
    }
  }
}
</style>
